<if condition="$count">
    <div class="sortlist mgt20">
        <h1>共 <{$count}> 个评论</h1>
    </div>
</if>
<style>
#CommentList .media-content {
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-left: 40px
}

#CommentList .media-repter {
    background-color: #F7F7F7;
    padding: 10px;
}
.reply_btn{ cursor: pointer; }
</style>
<div id="CommentList" class="mgt20 after_div">
    <volist name="data" id="vo">
        <div class="media media-comment-<{$vo.id}>">
            <div class="media-content" style="margin:0px;">
                <div class="answer-content "> 
                    <{$vo['content']}>
                </div>
                <if condition="$vo['comment']">
                    <div class="media-repter ">
                        <a style="color:#5cb85c" href="/User/index/user_id/<{$vo.comment.user_id}>" data-iduser="<{$vo.comment.user_id}>">
                            <{$vo.comment.user.nickname}>
                        </a>
                        <{:cutstr(strip_tags($vo[ 'comment'][ 'content']), "50")}>
                    </div>
                </if>
                <div class="muted mgt10">
                    <div class="s_left">
                        <a title="<{$vo.user.nickname}>" href="/User/index/user_id/<{$vo.user_id}>" target="_blank" class="small-avatar"> <img src="<{$vo.user.headimg}>" width="20" height="20"> <{$vo.user.nickname}></a> 
                       <span class="mgl10">  <{$vo[ 'time_tran']}></span>
                    </div>
                    <div class="pull-right"><span onclick="reply_btn(this)" ontouchstart="reply_btn(this)" class="reply_btn" data-nickname="<{$vo.user.nickname}>"  data-id="<{$vo.id}>"><i class="glyphicon glyphicon-comment " style="color: #ccc;" title="评论"></i></span>
                        </if>

                        <if condition="$vo['del_act'] eq 1"> <a class="mgl10" href="/BoxSns/Home/Index/del_comment/comment_id/<{$vo['id']}>" data-id="<{$vo.id}>" confirm="1" title="确认删除该评论吗？" class="del_btn" data-type="ajaxGet"><i class="glyphicon glyphicon-trash" style="color: #ccc;" title="删除"></i></a> </if>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </volist>
</div>
<include file="Public:pager" />
<div class="clearfix"></div>

<if condition="!$is_mobile">
<div class="sortlist mgt20">
    <h1>添加评论</h1>
</div>
<form action="/BoxSns/Home/Index/do_comment" id="addComment" class="mgt10" data-type="ajaxSubmit" method="post" style="padding-bottom:20px; ">
    <volist name="params['form']" id="vo">
        <input type="hidden" name="<{$key}>" value="<{$vo}>" />
    </volist>
    <input type="hidden" name="type" value="<{$params['type']}>" />
    <input type="hidden" name="pid" value="<{$params['topic_id']}>" />
    <input type="hidden" name="to_comment_id" value="0" />
    <textarea style="width:100%" class="addCommentTextarea" name="content" data-type="kindeditor" placeholder="请在这里输入你的评论"></textarea>
    <div class="col-md-4" style="float:right; text-align:right">
        <button id="btnAsk" type="submit" class="btn mgt20 btn-block btn-success btn-large a_bnt">评论</button>
    </div>
    <div class="clearfix"></div>
</form>
<script type="text/javascript">
$("#addComment").on("ajaxSubmitSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        hiApp.alert(data.msg)
    } else {
        hiApp.alert("提交成功");
        $("#addComment").find('[data-type="kindeditor"]').val("");
        $("#addComment").find('[data-type="kindeditor"]').trigger("kindeditorChange");
        box_render(data.msg, $("#answerListItemHtml").html(), $("#CommentList"), "append");
    }
})
</script>
</if>
<script type="text/html" id="answerListItemHtml">
<div>
<div class="media media-comment-{{items.id}}">
            <div class="media-content" style="margin:0px;">
                <div class="answer-content "> 
                    {{#items['content']}}
                </div>
                <div class="muted mgt10">
                    <div class="s_left">
                        <a title="{{items.user.nickname}}" href="/User/index/user_id/{{items.user_id}}" target="_blank" class="small-avatar"> <img src="{{items.user.headimg}}" width="20" height="20"> </a>
                       {{items['time_tran']}}
                    </div>
                    <div class="pull-right"><a   onclick="reply_btn(this)" ontouchstart="reply_btn(this)" data-nickname="<{$vo.user.nickname}>"  data-id="{{items.id}}"><i class="glyphicon glyphicon-comment" style="color: #ccc;" title="评论"></i></a>
                        </if>
                   
                        <if condition="$vo['del_act'] eq 1"> <a href="/BoxSns/Home/Index/del_comment/comment_id/{{items.id}}" data-id="{{items.id}}" confirm="1" title="确认删除该评论吗？" class="del_btn" data-type="ajaxGet"><i class="glyphicon glyphicon-trash"  style="color: #ccc;" title="删除"></i></a> </if>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
 </div>
</div>
</script>
<script type="text/javascript">


//$(function(){
$(".best_btn").on("ajaxGetSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        dialog(data.msg);
    } else {
        dialog("评论采纳成功");
        $(this).parents(".media-content").find(".bnt_best_tag").show();
        $(this).parents("#CommentList").find(".best_btn").parent().hide();
    }
})

$(".del_btn").on("ajaxGetSuccess", function(e, content) {
    var data = JSON.parse(content);
    if (data.error > 0) {
        dialog(data.msg);
    } else {
        dialog("删除成功");
        var id = $(this).attr("data-id");
        $(".media-comment-" + id).hide();
    }
})

// $(function(){
//     $(".reply_btn").unbind(hiApp.device.click).bind(hiApp.device.click,function(){
//      reply_btn(this);
//     })
// })



//})
function clearRe(_this){
   $("#addComment").find("[name='to_comment_id']").val(0); 
    $(".addCommentTextarea").val("");
    $(".addCommentTextarea").attr("placeholder", "请在这里输入你的评论")
}

function reply_btn(_this) {
    var to_comment_id = $(_this).attr("data-id");
    var nickname = "@" + $(_this).attr('data-nickname');
    $("#addComment").find("[name='to_comment_id']").val(to_comment_id);
    if(view_type=="Web"){
        $("#btnAsk").focus();
    } 
    $(".addComment").focus();
    $(".addCommentTextarea").attr("placeholder", nickname);
    $(".addCommentTextarea").val("");
   if($("#addCommentDiv").length>0){
        hiApp.popup("#addCommentDiv");
   }
   
}
</script>
